package threadDemo;

public class Demo3 {
    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();
        Thread t3 = new Thread(() -> {
            synchronized (lock1) {
                try {
                    System.out.println("t3 wait()方法之前");
                    lock1.wait();
                    System.out.println("t3 wait()方法之后");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread t1 = new Thread(() -> {
            synchronized (lock1) {
                try {
                    System.out.println("t1 wait()方法之前");
                    lock1.wait();
                    System.out.println("t1 wait()方法之后");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });


        Thread t2 = new Thread(() -> {
            synchronized (lock1) {
                lock1.notifyAll();
                System.out.println("唤醒wait()方法");
            }
        });
        t3.start();
        t1.start();
        t2.start();
    }
}
